﻿using JetBrains.Annotations;
using Missbot.AIModule.Base;
using Missbot.Core.Base;
using Missbot.Core.Cache;
using Missbot.Core.Common;
using Missbot.Model.MsgCmds.Following;

namespace Missbot.AIModule.Modules.Following
{
    [UsedImplicitly]
    public class FollowingMod : IAIModule
    {
        public override string Name => "关注";
        public override string ParentTag => "嘟嘟互动";

        [ModuleEnter(Command = "关注我", Description = "让机器人关注你（发送关注请求）")]
        public bool EnableAutoReaction(InboxSession session)
        {
            var user = Requestor.GetUserByUserName(session.User.UserName, session.User.Host);
            if (user.IsFollowing)
            {
                session.SendBack("已经关注你啦！不能重复关注的哦！");
                return false;
            }

            if (user.HasPendingFollowRequestFromYou)
            {
                session.SendBack("已经发送过关注申请啦！请先同意或拒绝我的关注申请！");
                return false;
            }
            
            MsgSender.PushMsg(new FollowingCreateCmd {UserID = session.User.ID});
            session.SendBack("已发送关注请求！");
            return true;
        }
    }
}